Page({
    data: {
      userInfo: null,
      orderCount: {
        unpaid: 0,
        unsent: 0,
        unreceived: 0,
        uncommented: 0,
        refund: 0
      },
      couponCount: 0,
      isLogin: false
    },
  
    onShow() {
      // 每次页面显示时检查登录状态
      this.checkLoginStatus();
    },
  
    checkLoginStatus() {
      const userInfo = wx.getStorageSync('userInfo');
      const token = wx.getStorageSync('token');
      
      if (userInfo && token) {
        // 已登录状态
        this.setData({
          userInfo: userInfo,
          isLogin: true
        });
        // 获取订单数据
        this.getOrderData();
        // 获取优惠券数据
        this.getCouponData();
      } else {
        // 未登录状态
        this.setData({
          userInfo: null,
          isLogin: false
        });
      }
    },
  
    getOrderData() {
      // 模拟获取订单数据
      setTimeout(() => {
        this.setData({
          orderCount: {
            unpaid: 2,
            unsent: 1,
            unreceived: 0,
            uncommented: 3,
            refund: 1
          }
        });
      }, 500);
    },
  
    getCouponData() {
      // 模拟获取优惠券数据
      setTimeout(() => {
        this.setData({
          couponCount: 3
        });
      }, 500);
    },
  
    goToUserInfo() {
      if (!this.data.isLogin) {
        wx.navigateTo({
          url: '/pages/login/login'
        });
        return;
      }
      wx.navigateTo({
        url: '/pages/my/info/info'
      });
    },
    navigateTo(e) {
      const url = e.currentTarget.dataset.url;
      wx.navigateTo({
          url: `/${url}`
      });
  },

  });